home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1627 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: yama.mcc.ac.uk!rmplc!news
  2. From: tsg38c@mailbox.rmplc.co.uk (TSG 38c)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: directories listing
  5. Date: 15 Jan 1996 18:09:51 GMT
  6. Organization: RMPLC
  7. Message-ID: <4de59f$kdb@spider.rmplc.co.uk>
  8. References: <4dckfq$4um@news.ust.hk>
  9. Reply-To: tsg38c@rmplc.co.uk
  10. NNTP-Posting-Host: rmplcdyn-19.rmplc.co.uk
  11. X-Newsreader: WinVN 0.92.6+
  12.  
  13. In article <4dckfq$4um@news.ust.hk>, cs_lcm@ug.cs.ust.hk (Lee Chun Man Raymond) says:
  14. >
  15. >
  16. >Hi,
  17. >
  18. >        I wrote a C program that needs to print out a listing of  
  19. >sub-directories of current working directory.
  20. >
  21. >The following is part of my program : ( Turbo C++ )
  22. >
  23. >struct find_t current_file;
  24. >int done; 
  25. >.........
  26. >printf("Directories listing : \n");
  27. >done = _dos_findfirst(full_path , FA_DIREC, ¤t_file); 
  28. >while (!done) {
  29. >   strcpy(file_path, path_name);
  30. >   strcat(file_path, "\\");
  31. >   strcat(file_path, current_file.name)
  32. >   printf("--> %s\n",file_path);
  33. >   done = _dos_findnext(¤t_file);
  34. >} 
  35. >
  36. >I don't know why it lists out all file including the sub-directories, but
  37. >I only want to lists our those sub-directories.
  38. >
  39. >Would someone help me?
  40. >
  41.  
  42. The dos findfirst/findfirst commands finds all file matching the normal
  43. files attributes and the attribute you specify. If you change you program to 
  44. the listing below it should work.
  45.  
  46. printf("Directories listing : \n");
  47. done = _dos_findfirst(full_path , FA_DIREC, ¤t_file); 
  48. while (!done) {
  49.  if (current_file.attrib & FA_DIREC){ 
  50.    strcpy(file_path, path_name);
  51.    strcat(file_path, "\\");
  52.    strcat(file_path, current_file.name)
  53.    printf("--> %s\n",file_path);
  54.   }
  55.  done = _dos_findnext(¤t_file);
  56.  
  57.  
  58.  
  59. Gary.
  60.